<!--
 * @Descripttion: 参与领取客户
 * @Author: xiao li
 * @Date: 2020-07-06 12:17:07
 * @LastEditors: xiao li
 * @LastEditTime: 2021-04-29 11:35:03
-->
<template>
    <div class="lb-sys-sproconfig">
        <top-nav :title="navTitle" :isBack="true"></top-nav>
        <div class="page-main">
          <el-row class="page-search-form">
            <el-form
            :inline="true"
            :model="searchForm"
            ref="searchForm"
            >
              <el-form-item label="参与状态" prop="status">
                <el-select v-model="searchForm.status" placeholder="请选择">
                    <el-option
                    v-for="item in statusOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <lb-button size="medium" type="primary" icon="el-icon-search" style="margin-right:5px" @click="getTableDataList(1)">{{$t('action.search')}}</lb-button>
                <lb-button size="medium" icon="el-icon-refresh-left" style="margin-right:5px" @click="resetForm('searchForm')">{{$t('action.reset')}}</lb-button>
              </el-form-item>
            </el-form>
          </el-row>

            <el-table
            v-loading="loading"
            :data="tableData"
          :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
            style="width: 100%">
            <el-table-column
              prop="nickName"
              label="用户昵称">
            </el-table-column>
            <el-table-column
              prop="coupon_name"
              label="邀请人数">
              <template slot-scope="scope">
                <span v-if="scope.row.use_condition === 1">{{scope.row.have_num +'人 | '+scope.row.user_num}}人</span>
                <span v-else>--</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="status"
              label="参与状态">
              <template slot-scope="scope">
                <span>{{scope.row.status === 1 ? '已完成':'未完成'}}</span>
              </template>
            </el-table-column>
          </el-table>

        <lb-page
          :batch='false'
          :page='searchForm.page'
          :pageSize='searchForm.limit'
          :total='total'
          @handleSizeChange='handleSizeChange'
          @handleCurrentChange='handleCurrentChange'
          >
        </lb-page>
        </div>
    </div>
</template>

<script>
export default {
  data () {
    return {
      navTitle: '',
      statusOptions: [
        {label: '已参与', value: 999},
        {label: '未完成', value: -1},
        {label: '已完成', value: 1}
      ],
      loading: false,
      total: 0,
      searchForm: {
        status: 999,
        active_id: 0,
        staff_id: 0,
        page: 1,
        limit: 10
      },
      tableData: []
    }
  },
  created () {
    let { id, uid } = this.$route.query
    this.searchForm.active_id = id
    this.searchForm.staff_id = uid
    this.getTableDataList()
  },
  methods: {
    resetForm (name) {
      this.$refs[name].resetFields()
      this.getTableDataList(1)
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    },
    async getTableDataList (flag) {
      if (flag) this.searchForm.page = 1
      this.loading = true
      let {searchForm} = this
      let {code, data} = await this.$api.cashRecordList(searchForm)
      this.loading = false
      if (code !== 200) return
      this.tableData = data.data
      this.total = data.total
      this.navTitle = `已参与领取“${data.staff_name}”发放此新客福包的客户`
    }
  }
}
</script>

<style lang="scss" scoped>
.el-input,
.el-select{
  width: 200px;
}
</style>
